package com.yk.framework.gui.wf.ui.form;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import com.yk.framework.gui.ctrl.YKDialog;

/**
 * @author lifetime
 *
 */
public class ScriptForm extends AbstractTemplateForm {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JTextField txtScriptCode;
	private JTextField txtScriptName;
	private JButton btnCancel;
	private JButton btnOK;
	
	
	public ScriptForm(YKDialog ownerFrame, JLabel lbl) {
		super(ownerFrame, lbl);
		initGUI();
	}

	public void loadFields() {
		txtScriptName.setText(editData.getString("nodeName"));
		txtScriptCode.setText(editData.getString("script"));
	}

	public void storeFields() {
		editData.put("nodeName", txtScriptName.getText());
		editData.put("script", txtScriptCode.getText());
	}

	private void initGUI() {
		try {
			addKeyListener(ownerFrame);
			this.setPreferredSize(new java.awt.Dimension(400, 256));
			this.setLayout(null);
			{
				jLabel1 = new JLabel();
				this.add(jLabel1);
				jLabel1.setText("\u811a\u672c\u540d\u79f0");
				jLabel1.setBounds(21, 19, 72, 17);
				jLabel1.addKeyListener(ownerFrame);
			}
			{
				txtScriptName = new JTextField();
				this.add(txtScriptName);
				txtScriptName.setBounds(105, 16, 157, 24);
				txtScriptName.addKeyListener(ownerFrame);
			}
			{
				jLabel2 = new JLabel();
				this.add(jLabel2);
				jLabel2.setText("\u811a\u672c\u4ee3\u7801");
				jLabel2.setBounds(21, 62, 79, 17);
				jLabel2.addKeyListener(ownerFrame);
			}
			{
				txtScriptCode = new JTextField();
				this.add(txtScriptCode);
				txtScriptCode.setBounds(105, 59, 283, 24);
				txtScriptCode.addKeyListener(ownerFrame);
			}
			{
				btnOK = new JButton();
				btnOK.addKeyListener(ownerFrame);
				btnOK.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						storeFields();
						lbl.putClientProperty("editData", editData);
						ownerFrame.setVisible(false);
						setCancel(false);
					}
				});
				this.add(btnOK);
				btnOK.setText("\u786e\u5b9a");
				btnOK.setBounds(300, 200, 76, 24);
			}
			{
				btnCancel = new JButton();
				btnCancel.addKeyListener(ownerFrame);
				btnCancel.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						ownerFrame.setVisible(false);
						setCancel(true);
					}
				});
				this.add(btnCancel);
				btnCancel.setText("\u53d6\u6d88");
				btnCancel.setBounds(200, 200, 80, 24);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
